package deconstruction.common;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import deconstruction.deconTable.ContainerDeconstructionTable;
import deconstruction.deconTable.GuiDeconstruction;

public class BlockDeconstructionTable extends Block{
	@SideOnly(Side.CLIENT)
	private Icon workbenchIconTop;
	@SideOnly(Side.CLIENT)
	private Icon workbenchIconFront;
	

	public BlockDeconstructionTable(int par1){
		super(par1, Material.wood);
		this.setCreativeTab(CreativeTabs.tabDecorations);
	}
	
	@SideOnly(Side.CLIENT)
	/**
	 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
	 */
	public Icon getIcon(int par1, int par2)
	{
		return par1 == 1 ? this.workbenchIconTop : (par1 == 0 ? Block.planks.getBlockTextureFromSide(par1) : (par1 != 2 && par1 != 4 ? this.blockIcon : this.workbenchIconFront));
	}

	@SideOnly(Side.CLIENT)

	/**
	 * When this method is called, your block should register all the icons it needs with the given IconRegister. This
	 * is the only chance you get to register icons.
	 */
	@Override
	public void registerIcons(IconRegister par1IconRegister)
	{
		this.blockIcon = par1IconRegister.registerIcon("deconstruction:Decon_Side");
		this.workbenchIconTop = par1IconRegister.registerIcon("deconstruction:Decon_Top");
		this.workbenchIconFront = this.blockIcon;
	}

	/** Called when the block is right clicked upon.
	 * @param
	 */
	public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer player, int var6, float var7, float var8, float var9){
		if (!player.isSneaking()){
			player.openGui(mod_Deconstruction.instance, 1, par1World, x, y, z);
			ContainerDeconstructionTable.getInstance().setCurrentRecipeIndex(0);
			GuiDeconstruction.currentRecipeIndex = 0;
			return true;
		}else{
			return false;
		}
	}
}